#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>

using namespace std;

int smallestValue(int n) {
    while (true)
    {
        int x = n, s = 0;
        for (int i = 2; i * i <= x; i++)
            while (x % i == 0)
            {
                s += i;
                x /= i;
            }
        if (x > 1)   s += x;
        if (s == n)  return n;
        n = s;
    }
}